-
Ginger Bill: "C11 is the last version of C that I will use. All other versions after that are not C anymore."
Note
-
The comments below were taken from A Reply to Let's Stop Copying C - Ginger Bill .
-
I agree with all the points below.
Type first
-
C’s “type first” was a weird design decision. It was meant to express that the type declaration is the same as how it is used in an expression.
-
For this reason, C has given us some of the most “wonderful” declarations:
int *x[3]; // array 3 of pointer to int
int (*x)[3]; // pointer to array 3 of int
_Atomic unsigned long long int const volatile *restrict foo[]; // Yeah...
-
And not to mention that type qualifiers can be in different places and still mean the same thing:
int const x;
const int x;
const int *y;
int const *y;
-
C’s approach also requires a symbol table while parsing to disambiguate between type declarations and an expression e.g.:
foo * bar; // Is this an expression or a declaration? You need to check the symbol table to find out
Weak typing
-
C’s implicit numeric conversions and array demotion to pointer conversion are a source of many bugs and confusions.
-
C++ tried to fix some of this but still its type system is quite weak in many regards.
typedef int My_Int;
int x = 123;
My_Int y = x; // this is allowed as `My_Int` is just an alias of `int`
Strings
-
C’s null-terminated strings made sense back in the day but not anymore.
-
Storing the length with the pointer to the data is personally my preferred approach, as this allows for substrings very easily.
-
#include
-
Back in the day when C was made, it is perfectly understandable why
#includewas used over different approaches. C was designed to be implementable with a single-pass compiler. -
However, since the advent of more modern computers, this approach is not needed and a proper library/module/package system is a better solution.
-
C++ approach with
namespaces is not a solution and more of a hack.
switch
-
Default fallthrough is painful.
-
Use break in every case.
-
Increment and Decrement
-
++and--are expressions which allow for things like*ptr++andarray[index++]to be done. -
However, in a language that does not require these “hacks”, these operators are quite useless .
-
Another issue is that order of evaluation for
++is undefined behavior in C, soarray[index++] = ++index;is not a good idea.
Single returns and out parameters
-
yeah.
Silent Errors
-
To develop.
Bitwise operator precedence
-
C’s operator precedence for bitwise operations is bad and requires an “overuse” of parentheses.